package com.hzit.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hzit.entity.PageResult;
import com.hzit.entity.Student;
import com.hzit.mapper.StudentMapper;
import com.hzit.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements IStudentService {

	@Autowired
	private StudentMapper studentMapper;
	//1. 列表学生
	@Override
	public List<Student> findAll() {
		return studentMapper.selectByExample(null);
	}

	//2. 分页查询
	@Override
	public PageResult<Student> findByPage(int page, int pageSize) {
		//2.1 开始分页
		PageHelper.startPage(page,pageSize);
		//2.2 查询所有记录
		List<Student> students = studentMapper.selectByExample(null);
		//2.3 转换为Page对象
		Page<Student> studentPage = (Page<Student>) students;
		//2.4 返回分页对象
		return new PageResult<>(studentPage.getResult(),studentPage.getTotal());
	}
}
